import 'package:flutter/material.dart';
import 'package:flutter_picker/flutter_picker.dart';
import 'package:flutter_project/config/theme_color.dart';

const Color kTitleColor = Color(0xFF333333);
const double kTextFontSize = 14;
const double kPickerHeight = 260.0;
const double kItemHeight = 40.0;

class PickNameUtils {
  static void showStringPicker<T>(
    BuildContext context, {
    List<T>? data,
    String? title,
    int? normalIndex,
    PickerDataAdapter? adapter,
    PickerConfirmCallback? clickCallBack,
  }) {
    openModalPicker(context,
        adapter: adapter ?? PickerDataAdapter(pickerData: data, isArray: false),
        clickCallBack: clickCallBack,
        selecteds: [normalIndex ?? 0],
        title: title!);
  }

  static void openModalPicker(
    BuildContext context, {
    PickerAdapter? adapter,
    String? title,
    List<int>? selecteds,
    PickerConfirmCallback? clickCallBack,
  }) {
    Picker(
            adapter: adapter!,
            title: Text(
              title!,
              style: const TextStyle(
                  color: kTitleColor,
                  fontSize: 16,
                  fontWeight: FontWeight.w500),
            ),
            headerColor: Colors.white,
            headerDecoration: BoxDecoration(
                color: Colors.white,
                border:
                    Border(bottom: BorderSide(color: ThemeColor.lineColor))),
            selecteds: selecteds,
            cancelText: '取消',
            confirmText: '确定',
            cancelTextStyle: TextStyle(
              color: ThemeColor.textColorSecond,
              fontSize: kTextFontSize,
            ),
            confirmTextStyle: TextStyle(
              color: ThemeColor.mainColor,
              fontSize: kTextFontSize,
            ),
            textAlign: TextAlign.right,
            itemExtent: kItemHeight,
            height: kPickerHeight,
            selectedTextStyle:
                const TextStyle(color: Color(0xff333333), fontSize: 20),
            textStyle: const TextStyle(color: Color(0xff9f8f8f), fontSize: 18),
            onConfirm: clickCallBack)
        .showModal(context);
  }
}
